package com.csd.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.csd.model.OtherPlase;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * Servlet implementation class OtherplacesServlet
 */
@WebServlet("/OtherplacesServlet")
public class OtherplacesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OtherplacesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		System.out.println("123456");
		String otherplaces = request.getParameter("otherplaces");
		String cartypename = request.getParameter("cartypename");
		String amt = request.getParameter("amt");
		String average = request.getParameter("average");
		JSONArray array = JSONArray.fromObject(otherplaces);
		List<OtherPlase> list = new ArrayList<OtherPlase>();
		for (int i = 0; i < array.size(); i++) {
			JSONObject otherJson = JSONObject.fromObject(array.get(i));
			String tradareaPlaceName = otherJson.getString("TradareaPlaceName");
			String cartypeid = otherJson.getString("cartypeid");
			String address = otherJson.getString("Address");
			String sTime = otherJson.getString("sTime");
			String eTime = otherJson.getString("eTime");
			String phone = otherJson.getString("Phone");
			String longitude = otherJson.getString("longitude");
			String latitude = otherJson.getString("latitude");
			String traffice = otherJson.getString("Traffice");
			String placeID = otherJson.getString("PlaceID");
			OtherPlase other = new OtherPlase();
			other.setTradareaPlaceName(tradareaPlaceName);
			other.setCartypeid(cartypeid);
			other.setAddress(address);
			other.setsTime(sTime);
			other.seteTime(eTime);
			other.setPhone(phone);
			other.setLongitude(longitude);
			other.setLatitude(latitude);
			other.setTraffice(traffice);
			other.setPlaceId(placeID);
			list.add(other);
		}
		request.getSession().setAttribute("otherList", list);
		request.getSession().setAttribute("cartypename", cartypename);
		request.getSession().setAttribute("average", average);
		request.getSession().setAttribute("amt", amt);
		response.sendRedirect("www/ChangeCarShop.jsp");
	}

}
